package xyz.ddlnt.servicemq.listener;

import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;
import xyz.ddlnt.model.dto.UserContentInteractionDTO;
import xyz.ddlnt.servicemq.service.PrivateMessageListService;

import java.util.Map;

/**
 * @author ZZULI_SE 210910
 * @data 2025/5/26 19:44
 */
@Slf4j
@Component
public class PrivateMessageListListener {
    @Resource
    private PrivateMessageListService privateMessageListService;


    /**
     * 更新接收方（用户）状态为已删除
     * @param userContentInteractionDTO
     */
    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(name = "receiver_status_delete"),
            exchange = @Exchange(name =  "usr.private_message_list"),
            key = "receiver_status_delete"
    ))
    public void receiverStatusDelete(UserContentInteractionDTO userContentInteractionDTO) {
        privateMessageListService.receiverStatusDelete(userContentInteractionDTO);
        log.info("更新接收方（用户）状态为已删除");
    }

    /**
     * toSid未读消息+1
     * @param map
     */
    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(name = "unread_messages_plus_one"),
            exchange = @Exchange(name =  "usr.private_message_list"),
            key = "unread_messages_plus_one"
    ))
    public void unreadMessagesPlusOne(Map<String, String> map) {
        log.info("开始：toSid未读消息+1");
        privateMessageListService.unreadMessagesPlusOne(map);
        log.info("toSid未读消息+1");
    }
}
